package com.example.demo.blog.controller;

import com.baomidou.mybatisplus.solon.plugins.pagination.Page;
import com.example.demo.blog.dto.BlogDTO;
import com.example.demo.blog.dto.req.BlogReq;
import com.example.demo.blog.dto.req.BlogSearchReq;
import com.example.demo.blog.mapper.BlogMapper;
import com.example.demo.blog.service.BlogService;
import com.example.demo.core.web.core.controller.BaseController;
import com.example.demo.core.web.core.model.CommonResult;
import com.example.demo.core.web.core.model.PageReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Validated;

/**
 * 自动发现表 控制器
 *
 * @author Airhead
 */
@Api(tags = {"博文 服务"})
@Controller
@Mapping(value = "/admin-api/blog")
public class BlogController extends BaseController {
  @Inject private BlogService service;

//  @Db private BlogMapper blogMapper;

  @ApiOperation("获取列表")
  @Post
  @Mapping("list")
  public CommonResult<List<BlogDTO>> list(BlogSearchReq searchReq) {
    return CommonResult.success(service.list(searchReq));
  }

  //  @ApiOperation("获取列表2")
  //  @Post
  //  @Mapping("list2")
  //  public CommonResult<List<BlogDTO>> list2(BlogSearchReq searchReq) {
  //    return CommonResult.success(blogMapper.list(searchReq));
  //  }

  @ApiOperation("获取列表-分页")
  @Post
  @Mapping("paginate")
  public CommonResult<Page<BlogDTO>> paginate(BlogSearchReq searchReq, PageReq pageReq) {
    return CommonResult.success(service.paginate(searchReq, pageReq));
  }

  @ApiOperation("添加")
  @Post
  @Mapping("add")
  public CommonResult<Boolean> add(@Body @Validated(BlogReq.Add.class) BlogReq req) {
    return CommonResult.success(service.add(req));
  }

  @ApiOperation("更新")
  @Post
  @Mapping("update")
  public CommonResult<Boolean> update(@Body @Validated(BlogReq.Update.class) BlogReq req) {
    return CommonResult.success(service.update(req));
  }

  @ApiOperation("删除")
  @Post
  @Mapping("delete")
  public CommonResult<Boolean> delete(@Param("id") List<Integer> idList) {
    return CommonResult.success(service.delete(idList));
  }

  @ApiOperation("获取")
  @Post
  @Mapping("get")
  public CommonResult<BlogDTO> get(@Param("id") Integer id) {
    return CommonResult.success(service.get(id));
  }
}
